<?php
$w = new sfWidgetFormChoice(array(
            'choices' => array('Fabien Potencier', 'Fabian Lange'),
        ));
$w = new sfWidgetFormChoice(array(
            'multiple' => true,
            'choices'  => array('PHP', 'symfony', 'Doctrine', 'Propel', 'model'),
        ));
$w = new sfWidgetFormChoice(array(
            'expanded' => true,
            'choices'  => array('published', 'draft', 'deleted'),
        ));

$w = new sfWidgetFormChoice(array(
            'expanded' => true,
            'multiple' => true,
            'choices'  => array('A week of symfony', 'Call the expert', 'Community'),
        ));
$choices = array(
    'Europe' => array(
        'France'  => 'France',
        'Spain'   => 'Spain',
        'Italy'   => 'Italy'),
    'America' => array(
        'USA'     => 'USA',
        'Canada'  => 'Canada',
        'Brazil ' => 'Brazil'),
);

$w = new sfWidgetFormChoice(array('choices' => $choices));

$w = new sfWidgetFormChoice(array(
            'choices'  => $choices,
            'expanded' => true,
        ));

$w = new sfWidgetFormChoice(array(
            'choices'          => $choices,
            'expanded'         => true,
            'renderer_options' => array('template' => '<strong>%group%</strong> %options%'),
        ));

$w = new sfWidgetFormChoice(array(
            'choices'  => $choices,
            'multiple' => true,
        ));
$w         = new sfWidgetFormChoice(array(
            'choices'          => $choices,
            'multiple'         => true,
            'expanded'         => true,
            'renderer_options' => array(
                'template'        => '<strong>%group%</strong> %options%',
                'label_separator' => 'label_separator ',
                'class'           => 'class',
                'separator'       => 'separator',
            #'formatter'       => 'strong>%group%</strong> <i>%option%</i>',
            ),
        ));

//        $w = new sfWidgetFormChoice(array(
//                    'choices' => array('PHP', 'symfony', 'Doctrine', 'Propel', 'model'),
//                    'renderer_class' => 'sfWidgetFormSelectDoubleList',
//                ));
//        $w = new sfWidgetFormChoice(array(
//  'choices'          => array(),
//  'renderer_class'   => 'sfWidgetFormJQueryAutocompleter',
//  'renderer_options' => array('url' => '/autocomplete_script'),
//));


$w = new sfWidgetFormDate(array('format' => '%year% - %month% - %day%'));
$years   = range(2009, 2020);
$w       = new sfWidgetFormDate(
                array('years'  => array_combine($years, $years),
                    'format' => '%year% - %month% - %day%',
                )
);
$w       = new sfWidgetFormTime();
$w       = new sfWidgetFormTime(array('with_seconds' => true));
$w             = new sfWidgetFormTime(array(
            'with_seconds' => true,
            'format'       => '%hour% : %minute% : %second%',
        ));
$seconds       = array(0, 15, 30, 45);
$w = new sfWidgetFormTime(array(
            'with_seconds' => true,
            'seconds'      => array_combine($seconds, $seconds),
        ));

$w = new sfWidgetFormI18nDate(array('culture'      => 'en',
            'month_format' => 'short_name',
        ));
$w             = new sfWidgetFormI18nTime(array('culture' => 'ar'));
$w        = new sfWidgetFormDateRange(array(
            'from_date' => new sfWidgetFormDate(),
            'to_date'  => new sfWidgetFormDate(), 'template' => 'Begin at: %from_date%<br />End at: %to_date%',
        ));
$w         = new sfWidgetFormI18nChoiceCountry(array('culture' => 'fr'));
$w        = new sfWidgetFormI18nChoiceCurrency(array('culture' => 'en'));
$w        = new sfWidgetFormI18nChoiceTimezone(array('culture' => 'fr'));
//     $w = new sfWidgetFormReCaptcha(array(
//  'public_key' => 'RECAPTCHA_PUBLIC_KEY'
//));   
$w        = new sfWidgetFormSchema(array('name' => new sfWidgetFormInputText()));
$w->setDefault('name', 'Fabien');
// which is equivalent to
$w['name']->setDefault('Fabien');
// or
$w->setDefaults(array('name'       => 'Fabien'));

$ws = new sfWidgetFormSchema(array(
'first_name' => new sfWidgetFormInputText(),
'last_name' => new sfWidgetFormInputText()
));
 
$ws->moveField('first_name', sfWidgetFormSchema::AFTER, 'last_name');
      $ws->setPositions(array('last_name', 'first_name'));  
      
      $ws = new sfWidgetFormSchema(array('name' => new sfWidgetFormInputText()));
$wd = new sfWidgetFormSchemaDecorator($ws, '<table>%content%</table>');protected static $subjects = array('Subject A', 'Subject B', 'Subject C');

    public function configure()
    {
//      $this->setWidgetSchema(new sfWidgetFormSchema(array(
//  'name'    => new sfWidgetFormInputText(),
//  'email'   => new sfWidgetFormInputText(),
//  'message' => new sfWidgetFormTextarea(),
//)));
// almost equivalent to :
//        $this->widgetSchema = new sfWidgetFormSchema(array(
//                    'name'    => new sfWidgetFormInputText(),
//                    'email'   => new sfWidgetFormInputText(),
//                    'message' => new sfWidgetFormTextarea(),
//                ));
//
//        $this->widgetSchema->setFormFormatterName('list');
//        $this->widgetSchema->setNameFormat('contact[%s]');
//        $this->setDefault('email', 'Your Email Here');
//        $this->setDefaults(array('email' => 'Your Email Here', 'name'  => 'Your Name Here'));

        $this->setWidgets(array(
            'name'    => new sfWidgetFormInputText(),
            'email'   => new sfWidgetFormInputText(),
            'subject' => new sfWidgetFormSelect(array('choices' => self::$subjects)),
            'message' => new sfWidgetFormTextarea(),
        ));
        $this->widgetSchema->setNameFormat('contact[%s]');

        $this->setValidators(array(
            'name'    => new sfValidatorString(
                    array('required' => false)),
            'email'   => new sfValidatorEmail(
                    array(),
                    array('invalid' => 'The email address is invalid.')),
            'subject' => new sfValidatorChoice(
                    array('choices' => array_keys(self::$subjects))),
            'message' => new sfValidatorString(
                    array('min_length' => 4),
                    array(
                        'required'   => 'The message field is required',
                        'min_length' => 'The message "%value%" is too short. It must be of %min_length% characters at least.',
            )),
        ));//        $this->setWidgets(array(
//            'password'       => new sfWidgetFormInputPassword(),
//            'password_again' => new sfWidgetFormInputPassword(),
//        ));

//        $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare(
//                        'password', sfValidatorSchemaCompare::EQUAL, 'password_again'));

        $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('password', '==', 'password_again'));
        
        $this->validatorSchema->setPostValidator(
                new sfValidatorSchemaCompare('start_date', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'end_date',
                        array(),
                        array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")')
                )
        );

}       
        // echo $this->form['name']->renderRow();
        // echo $this->form['email']->renderRow();
        echo $this->form['subject']->renderRow();
        echo $this->form['message']->renderRow();class sfWidgetFormTrilean extends sfWidgetForm
{
  public function configure($options = array(), $attributes = array())
  {
 
    $this->addOption('choices', array(
      0 => 'No',
      1 => 'Yes',
      'null' => 'Null'
    ));
  }
 
  public function render($name, $value = null, $attributes = array(), $errors = array())
  {
    $value = $value === null ? 'null' : $value;
 
    $options = array();
    foreach ($this->getOption('choices') as $key => $option)
    {
      $attributes = array('value' => self::escapeOnce($key));
      if ($key == $value)
      {
        $attributes['selected'] = 'selected';
      }
 
      $options[] = $this->renderContentTag(
        'option',
        self::escapeOnce($option),
        $attributes
      );
    }
 
    return $this->renderContentTag(
      'select',
      "\n".implode("\n", $options)."\n",
      array_merge(array('name' => $name), $attributes
    ));
  }
  }class sfValidatorTrilean extends sfValidatorBase
{
  protected function configure($options = array(), $messages = array())
  {
    $this->addOption('true_values', array('true', 't', 'yes', 'y', 'on', '1'));
    $this->addOption('false_values', array('false', 'f', 'no', 'n', 'off', '0'));
    $this->addOption('null_values', array('null', null));
  }
 
  protected function doClean($value)
  {
    if (in_array($value, $this->getOption('true_values')))
    {
      return true;
    }
 
    if (in_array($value, $this->getOption('false_values')))
    {
      return false;
    }
 
    if (in_array($value, $this->getOption('null_values')))
    {
      return null;
    }
 
    throw new sfValidatorError($this, 'invalid', array('value' => $value));
  }
 
  public function isEmpty($value)
  {
    return false;
  }
}





?>